<?php

class EmploymentContractTypeDao extends BaseDao
{

    public function getEmploymentContractTypeList($sortField = 'code', $sortOrder = 'ASC', $activeOnly = true, $limit = null, $offset = null)
    {

        $sortField = ($sortField == "") ? 'code' : $sortField;
        $sortOrder = ($sortOrder == "") ? 'ASC' : $sortOrder;

        try {
            $q = Doctrine_Query :: create()
                ->from('EmploymentContractType');
            if ($activeOnly == true) {
                $q->addWhere('isDeleted = ?', EmploymentContractType::ACTIVE);
            }
            $q->orderBy($sortField . ' ' . $sortOrder);
            if (!empty($limit)) {
                $q->offset($offset)
                    ->limit($limit);
            }
            return $q->execute();
        } catch (Exception $e) {
            throw new DaoException($e->getMessage());
        }
    }

    public function deleteEmploymentContractType($toBeDeletedEmploymentContractTypeIds)
    {

        try {
            $q = Doctrine_Query :: create()
                ->update('EmploymentContractType')
                ->set('isDeleted', '?', EmploymentContractType::DELETED)
                ->whereIn('id', $toBeDeletedEmploymentContractTypeIds);
            return $q->execute();
        } catch (Exception $e) {
            throw new DaoException($e->getMessage());
        }
    }

    public function getEmploymentContractTypeById($employmentContractTypeId)
    {

        try {
            return Doctrine::getTable('EmploymentContractType')->find($employmentContractTypeId);
        } catch (Exception $e) {
            throw new DaoException($e->getMessage());
        }
    }

}

